let login = document.querySelector('#btn-login')




login.addEventListener('click', async function () {
    const data = serialize(document.querySelector('form'), { hash: true })// hash意思是 设置返回的data是对象类型

    if (!data.username || !data.password) {
        document.querySelector('#myToast .toast-body').innerHTML = "用户名/密码不能为空哦 😁"
        myToast.show();
        return
    }
    
    try{let  res = await axios({
        url: "/login",
        method: 'post',
        data,
    })
    document.querySelector('#myToast .toast-body').innerHTML = "登录成功"
    myToast.show();
    // console.log(res);
    // console.log(res.data.data.token);
    localStorage.setItem('token', res.data.data.token)
    setTimeout(() => {
        window.location.assign('./index.html')
    }, 1000)
}catch(err){
    console.dir(err);
    document.querySelector('#myToast .toast-body').innerHTML =err.response.data.message
        myToast.show();
    }
})






